import type { StringKeyObject } from 'my-ts-core/types';

export class DataSharingService {
  private static sharedData: StringKeyObject = {};

  /**
   * Gets the data with [key].
   */
  static get<T>(key: string): T {
    return this.sharedData[key] as T;
  }

  /**
   * Sets the data with [key] and [value].
   */
  static set(key: string, value: any): void {
    this.sharedData[key] = value;
  }

  /**
   * Removes the data by [keys].
   */
  static remove(keys: string[]): void {
    for (const key of keys) {
      delete this.sharedData[key];
    }
  }

  /**
   * Removes all data.
   */
  static removeAll(): void {
    for (const key in this.sharedData) {
      delete this.sharedData[key];
    }
  }
}
